﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>集团计划</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="../../static/css/font.css" rel="stylesheet" />
    <link href="../../static/css/weadmin.css" rel="stylesheet" />
    <link href="../../lib/layui/css/layui.css" rel="stylesheet" />
    <script src="../../../lib/layui/layui.js"></script>
   
</head>
<body>
    <div class="weadmin-nav">
        <span class="layui-breadcrumb" style="visibility: visible;">
            <a href="#">首页</a><span lay-separator="">/</span>
            <a href="#">培训计划</a><span lay-separator="">/</span>
            <a><cite>培训计划表</cite></a>
        </span>
        <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon" style="line-height:30px">ဂ</i>
        </a>
    </div>
    <div class="layui-fluid" id="infos">
        <table id="dataList" lay-filter="dataList"></table>
    </div>
    <div class="layui-fluid fluid-position">
        <div class="layui-form">
            <div class="layui-card">
                <div class="layui-card-header">
                    <div class="layui-row layui-col-space10 layui-btn-container">
                        <button type="button" class="layui-btn layui-btn-primary" id="find" name="查询"><i class="layui-icon">&#xe615;</i>查询</button>
                        <button type="button" class="layui-btn layui-btn-primary" id="reset" name="清空"><i class="layui-icon">&#xe669;</i>清空</button>
                        
                        <button type="button" class="layui-btn layui-btn-normal" hidden="hidden" id="addupload" name="添加上传"><i class="layui-icon">&#xe608;</i> 添加保存</button>
                        <button type="button" class="layui-btn layui-btn-normal" id="edit" lay-filter="edit" name="保存" lay-submit><i class="layui-icon">&#xe642;</i>保存</button>
                        <button type="button" class="layui-btn layui-btn-danger" id="del" name="删除"><i class="layui-icon">&#xe640;</i>删除</button>
                        <button type="button" class="layui-btn layui-btn-warm" id="check" name="审核"><i class="layui-icon">&#xe605;</i>审核</button>
                        <button type="button" class="layui-btn layui-btn-warm" id="uncheck" name="取消审核"><i class="layui-icon">&#x1006;</i>取消审核</button>
                        <button type="button" class="layui-btn layui-btn-normal" id="SendNext" lay-filter="edit" name="下发计划"><i class="layui-icon">&#xe642;</i>下发计划</button>
                        <!--<button type="button" class="layui-btn layui-btn-warm layui-bg-cyan" id="release" name="发布"><i class="layui-icon">&#xe609;</i>发布</button>-->
                        <!--<button type="button" class="layui-btn layui-btn-warm layui-bg-cyan" id="unrelease" name="取消发布"><i class="layui-icon">&#xe604;</i>取消发布</button>-->
                        <!--<button type="button" class="layui-btn" name="导入"><i class="layui-icon">&#xe638;</i>导入</button>
                        <button type="button" class="layui-btn" name="导出"><i class="layui-icon">&#xe632;</i>导出</button>
                        <button type="button" class="layui-btn" name="打印"><i class="layui-icon">&#xe63c;</i>打印</button>-->
                    </div>
                </div>
                <div class="layui-card-body">
                    <div class="layui-collapse"  lay-filter="infos_form">
                        <div class="layui-colla-item">
                            <h2 class="layui-colla-title">培训计划</h2>
                            <div class="layui-colla-content layui-show">
                                <div class="layui-form layui-form-pane">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">上级计划</label>
                                        <div class="layui-input-block">
                                            <input type="text" placeholder="上级计划" maxlength="50" class="layui-input" id="PrePlanName" name="PrePlanName" onclick="SelectGroup()" />
                                        </div>
                                    </div>
                                    <!--计划名称-->
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">计划名称</label>
                                        <div class="layui-input-block">
                                            <input type="text" placeholder="计划名称" value="" class="layui-input" maxlength="50" id="TPName" name="TPName" />
                                        </div>
                                    </div>

                                    <!--时间-->
                                    <div class="layui-form-item">
                                        <!--<label class="layui-form-label">计划编号</label>
        <div class="layui-input-inline">
            <input type="text" placeholder="计划编号" class="layui-input" maxlength="8" />
        </div>-->
                                        <div class="layui-inline">
                                            <label class="layui-form-label">发布时间</label>
                                            <div class="layui-input-inline">
                                                <input type="text" class="layui-input" id="TPReleaseStart" />
                                            </div>
                                            <label class="layui-form-label layui-form-label-inner layui-form-label-inner-w1">至</label>
                                            <div class="layui-input-inline layui-form-label-inner">
                                                <input type="text" class="layui-input" id="TPReleaseEnd" name="TPReleaseEnd" />
                                            </div>
                                        </div>
                                        <div class="layui-inline" style="display:none;">
                                            <label class="layui-form-label">发布</label>
                                            <div class="layui-input-block">
                                                <select id="TPIsRelease" class="layui-tree-more" name="TPIsRelease">
                                                    <option value="">请选择</option>
                                                    <option value="0">未发布</option>
                                                    <option value="1">已发布</option>
                                                </select>
                                            </div>
                                        </div>

                                    </div>
                                    <div class="layui-form-item" style="display:none;">
                                        <div class="layui-form-label">选择部门</div>
                                        <div class="layui-input-block">
                                            <input type="text" autocomplete="off" readonly="" id="selectDatas" name="selectDatas" placeholder="请选择" class="layui-input" />
                                            <div class="eleTree" lay-filter="data5"></div>
                                        </div>
                                    </div>

                                    <div class="layui-colla-item">
                                        <h2 class="layui-colla-title">课程内容</h2>
                                        <div class="layui-colla-content layui-show">
                                            <div class="layui-form layui-form-pane">
                                                <div class="layui-form-item">

                                                </div>
                                                <button type="button" class="layui-btn layui-btn-normal" id="insertContent1">新增</button>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-colla-item">
                                        <h2 class="layui-colla-title">每周两题</h2>
                                        <div class="layui-colla-content layui-show">
                                            <div class="layui-form layui-form-pane">
                                                <div class="layui-form-item">

                                                </div>
                                                <button type="button" class="layui-btn layui-btn-normal" id="insertContent2">新增</button>
                                            </div>
                                        </div>
                                    </div>

                                    <!--备注-->
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">备注</label>
                                        <div class="layui-input-block">
                                            <input type="text" placeholder="备注" class="layui-input" maxlength="150" id="Remarks" name="Remarks" />
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <div class="layui-row">
                                            <button type="button" class="layui-btn layui-btn-primary" id="test8">选择文件</button>
                                            <label class="layui-form-label">上传附件</label>

                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>

                </div>
                <div class="layui-card-header layui-btn-container">

                </div>
            </div>
        </div>
    </div>
    <script>
        var CurrentUserID = "";
        var ModleNameTip = "培训计划";  //模块名称  用于提示部门信息的内容
        var contollerName = "TrainPlan";
        var load = 1;
        var CPID = 0;
        var prePlanId = 0;
        var iscor = 0;
        var selectIDs = [];//选中的id列表 [可用批量删除  审核 取消 ]
        var selectCurrentID = 0;// 当前选中的 id  [用于修改]
        var currentDeptLevelId = 0;//当前登录者 部门级别  0：是段
        var currentInfoDeptLevelId = 0;//当前选中信息的  部门级别  [用于判断 是否能够对 该条信息进行修改:下级不能对上级的计划信息进行修改]
        var cuurentDeptId = 0;//当前部门id
        var vList1 = [];
        var vList2 = [];
        var dis1 = "fr_";
        var dis2 = "sr_";
        var v1max = 0;
        var v2max = 0;
        var selectCurrentIsCheckStatus = 0;// 当前选中的行的 IsChck 状态  [用于删除/审核/取消审核/发布/取消发布时判断]
        var selectCurrentIsReleaseStatus = 0;// 当前选中的行的 IsRelease 状态  [用于删除/审核/取消审核/发布/取消发布时判断]
        var currentInfoDeptId = 0;//当前选中信息的 部门id
        var selectobjs = [];//
        var dataSelect = [];
        var temp_deptId_List = [];
        var dataCurent = [];
        var th = 0;
        var tw = 0;
        function SelectGroup() {
            layui.use(['layer', 'jquery'], function () {
                var h = th * 1.8;
                var w = tw * 0.8;
                var layer = layui.layer;
                var $ = layui.jquery;
                var contentPage = "corpplan_SelectList.html";
                var title = "选择集团计划";
                iscor = 0;
                //if (currentDeptLevelId != 0) {
                //    contentPage = "trainplan_SelectList.html?plan=1";
                //    title = "选择上级培训计划";
                //    iscor = 1;
                //}
                layer.open({
                    title: title,
                    type: 2,
                    area: [w + "px", h + "px"],
                    btn: ['确定'],
                    content: contentPage,
                    yes: function (index) {
                        var res = window["layui-layer-iframe" + index].selectdata();
                        $("#PrePlanName").val(res.RefName);
                        prePlanId = res.RefID;
                        CPID = res.CPID;
                        layer.close(index);
                    }
                });

            });
        };
        function PlanSend() {
            if (selectCurrentID <= 0) {
                layer.msg("请选择一条信息!"); return;
            }
            layui.use(['layer', 'jquery'], function () {
                var h = th * 1.8;
                var w = tw * 0.8;
                var layer = layui.layer;
                var $ = layui.jquery;
                var contentPage = "PlanSend.html?TPID=" + selectCurrentID + "&TPName=" + selectobjs[selectobjs.length - 1].TPName + "";
                var title = "下发计划";
                layer.open({
                    title: title,
                    type: 2,
                    area: [w + "px", h + "px"],
                    //btn: ['确定'],
                    content: contentPage,
                    yes: function (index) {
                        //var res = window["layui-layer-iframe" + index].selectdata();
                        //$("#PrePlanName").val(res.RefName);
                        //prePlanId = res.RefID;
                        //CPID = res.CPID;
                        layer.close(index);
                    }
                });

            });
        };
        function SelectGroupTF(v) {
            layui.use(['layer', 'jquery'], function () {
                var h = th * 1.6;
                var w = tw * 0.8;
                var layer = layui.layer;
                var $ = layui.jquery;
                var contentPage = "../traincontent/file_SelectList.html";
                var title = "选择培训资料";
                layer.open({
                    title: title,
                    type: 2,
                    area: [w + "px", h + "px"],
                    btn: ['确定'],
                    content: contentPage,
                    yes: function (index) {
                        var res = window["layui-layer-iframe" + index].selectdata();
                        var SelectFileObjList = res.objList;
                        var TempFileNames = [];
                        FileListIds = [];
                        var files = [];
                        for (var i = 0; i < SelectFileObjList.length; i++) {
                            var item = SelectFileObjList[i];
                            TempFileNames.push(item.TFName);
                            files.push({ id: item.TFID, name: item.TFName });
                        }
                        var vs = $(v).parent().parent().attr("id").split("_");

                        if (vs[0] == dis1.split("_")[0]) {
                            for (var i = 0; i < vList1.length; i++) {
                                var item = vList1[i];
                                if (vList1[i].idx == vs[1]) {
                                    vList1.splice(i, 1);
                                    vList1.push({ idx: item.idx, CName: item.CName, files: files });
                                    break;
                                }
                            }
                        }
                        else {
                            for (var i = 0; i < vList2.length; i++) {
                                var item = vList2[i];
                                if (vList2[i].idx == vs[1]) {
                                    vList2.splice(i, 1);
                                    vList2.push({ idx: item.idx, CName: item.CName, files: files });
                                    break;
                                }
                            }
                        }

                        files = [];
                        $(v).val(TempFileNames.toString());
                        layer.close(index);
                    }
                });
            });
        }
        layui.use(['form', 'laydate', 'table', 'jquery', 'element', 'layer', 'tree', 'util', 'upload'], function () {
            var laydate = layui.laydate;
            var $ = layui.jquery;
            th = $(document).height() * 0.5;
            tw = $(document).width();
            var table = layui.table;
            var form = layui.form;
            var element = layui.element;
            var layer = layui.layer;
            var eleTree = layui.tree;
            var upload = layui.upload;
            $(function ($) { $.fn.layuiTextArea = function (options) { var defaults = { maxHeight: null, minHeight: $(this).height() }; var opts = $.extend({}, defaults, options); return $(this).each(function () { $(this).bind("paste cut keydown keyup focus blur", function () { var height, style = this.style; this.style.height = opts.minHeight + 'px'; if (this.scrollHeight > opts.minHeight) { if (opts.maxHeight && this.scrollHeight > opts.maxHeight) { height = opts.maxHeight; style.overflowY = 'scroll'; } else { height = this.scrollHeight; style.overflowY = 'hidden'; } style.height = height + 'px'; } }); }); }; });
            $(".layui-card-header").find("button").each(function () { if (PowerList.indexOf($(this).attr("name")) <= -1) { $(this).attr("style", "display:none;") } });
            form.on('switch(switch)', function (data) { });
            laydate.render({ elem: '#TPReleaseStart', trigger: 'click', type: 'datetime', format: 'yyyy-MM-dd HH:mm' });
            laydate.render({ elem: '#TPReleaseEnd', trigger: 'click', type: 'datetime', format: 'yyyy-MM-dd HH:mm' });
            function PageInit() {
                var obj = $("div[lay-id='dataList']");
                var child = $(".layui-table-body");
                var off = obj.offset().top;
                var c = th - off - 100;
                child.attr("style", "height:" + c + "px");
            }
            element.on('collapse(infos_form)', function (data) {
                PageInit();
            });
            function InitItem() {
                $("button[name='delitems']").off("click").on("click", function () { DelItems($(this).parent()); }); $("textarea[name='ZName']").off("click").on("click", function () { SelectGroupTF($(this)); }); $("textarea").layuiTextArea({ maxHeight: 500, })
            }
            function formRenderSelect() {
                form.render('select');
            }
            function formRenderCk() {
                form.render('checkbox');
            }
            $("#insertContent1").on("click", function () {
                p1();
            });
            $("#insertContent2").on("click", function () {
                p2();
            });
            function p1() {
                vList1.push({ idx: v1max, CName: "", files: [{ id: 0, name: "" }] });
                SetItems($("#insertContent1"), dis1, v1max); v1max++;
            }
            function p2() {
                vList2.push({ idx: v2max, CName: "", files: [{ id: 0, name: "" }] });
                SetItems($("#insertContent2"), dis2, v2max); v2max++;
            }
            function SetItemsValue(obj, cv, zv, tv) {
                $("#" + obj).find("textarea[name=CName]").val(cv);
                $("#" + obj).find("textarea[name=ZName]").val(zv);
                $("#" + obj).find("input[name=TCDuration]").val(tv);
                $("#" + obj).find("textarea[name=CName]").click();
            }
            function ClearItems(obj) {
                obj.parent().find(".layui-form-item").find(".layui-row").remove();
            }
            function SetItems(obj, dis, index) {
                var c = obj.parent().find(".layui-form-item");
                var v = "<div class=\"layui-row\" id=\"" + dis + index + "\">";
                v += "<div class=\"layui-input-md2 layui-input-row\">";// class=\"layui-textarea\"   style=\"resize:none;\"  rows=\"10\"
                v += " <textarea    placeholder=\"内容\" class=\"layui-textarea\"   name=\"CName\" ></textarea>";
                v += "</div>";
                v += "<div class=\"layui-input-md1 layui-input-row\">";
                v += " <textarea   placeholder=\"选择资料\" class=\"layui-textarea\"    name=\"ZName\" ></textarea>";
                v += "</div>";
                v += "<div class=\"layui-input-md3 layui-input-row\">";
                v += "<input type=\"text\" placeholder=\"学时\" maxlength=\"50\" class=\"layui-input layui-input-full\" name=\"TCDuration\"  />";
                v += "</div>";
                v += "<button type=\"button\" class=\"layui-btn layui-btn-danger\"  name=\"delitems\" >删除</button>";
                v += "</div>";
                c.append(v);
                InitItem();
            }
            function GetItems(obj, vlist) {
                var resultList = [];
                obj.parent().find(".layui-form-item").find(".layui-row").each(function () {
                    var vlistx = $(this).attr("id").split("_")[1];
                    for (var i = 0; i < vlist.length; i++) {
                        if (vlist[i].idx == vlistx) {
                            resultList.push({ idx: vlistx, CName: $(this).find("textarea[name=CName]:first").val(), files: vlist[i].files, TCDuration: $(this).find("input[name=TCDuration]:first").val() });
                        }
                    }
                });
                return resultList;
            }
            function DelItems(bobj) {
                var vs = $(bobj).attr("id").split("_");
                if (vs[0] == dis1.split("_")[0]) {
                    for (var i = 0; i < vList1.length; i++) {
                        if (vList1[i].idx == vs[1]) {
                            vList1.splice(i, 1);
                            $(bobj).remove();
                            break;
                        }
                    }
                }
                else {
                    for (var i = 0; i < vList2.length; i++) {
                        if (vList2[i].idx == vs[1]) {
                            vList2.splice(i, 1);
                            $(bobj).remove();
                            break;
                        }
                    }
                }
            }
            function empty() {
                ClearItems($("#insertContent1"));
                ClearItems($("#insertContent2"));
                vList1 = []; vList2 = []; v1max = 0; v2max = 0;
            }
            $(function () {
                p1(); p2(); InitItem();
            });
            $.ajax({
                url: ApiUrl + "Dep/DeptLevel",//SelTree
                type: 'post',
                headers: {
                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                },
                success: function (data) {
                    if (data.StatusCode == 200) {
                        currentDeptLevelId = data.Data.currentDeptLevelId;
                        cuurentDeptId = data.Data.cuurentDeptId;
                        UserID = data.Data.UserID;
                        //GetDept(cuurentDeptId);
                    }
                    else if (data.StatusCode == 403) {
                        layer.alert(data.Info, function () {
                            top.location.href = "http://" + top.location.host + "/login.html";
                        })
                    }
                    else {
                        layer.msg(data.Info);
                    }
                }
            });
            function GetSingleCourseContent(TPID) {
                $.ajax({
                    url: ApiUrl + "TrainPlan/GetContent?TPID=" + TPID,
                    type: 'get',
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    success: function (data) {
                        empty();
                        if (data.StatusCode == 200) {
                            vList1 = data.Data.vList1;
                            vList2 = data.Data.vList2;
                            for (var i = 0; i < vList1.length; i++) {
                                var item = vList1[i];
                                SetItems($("#insertContent1"), dis1, v1max);
                                SetItemsValue(dis1 + v1max, item.CName, item.files.map(function (v) { return v.name; }).toString(), item.TCDuration);
                                v1max++;
                            }
                            for (var i = 0; i < vList2.length; i++) {
                                var item = vList2[i];
                                SetItems($("#insertContent2"), dis2, v2max);
                                SetItemsValue(dis2 + v2max, item.CName, item.files.map(function (v) { return v.name; }).toString(), item.TCDuration);
                                v2max++;
                            }
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            if (data.Info != null) {
                                layer.msg(data.Info);
                            }
                        }
                    }
                });
            }
            //获取下级部门列表树
            //function GetDept(deptid) {
            //    var r = 0;
            //    $.ajax({
            //        url: ApiUrl + "Dep/SelNextTree",//SelTree
            //        type: 'post',
            //        async: false,
            //        headers: {
            //            "userid": JSON.parse(window.localStorage.authInfo).UserId,
            //            "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
            //        },
            //        data: { DepID: deptid },
            //        success: function (data) {
            //            if (data.StatusCode == 200) {
            //                dataSelect = data.Data;
            //                loadTree();
            //                r = 1;
            //            }
            //            else if (data.StatusCode == 403) {
            //                layer.alert(data.Info, function () {
            //                    top.location.href = "http://" + top.location.host + "/login.html";
            //                })
            //            }
            //            else {
            //                layer.msg(data.Info);
            //            }
            //        }
            //    });
            //    return r;
            //}
            function GetSinglePrePlanOrCorp(data) {
                iscor = 0;
                var apiUrl = "";
                if (data.TPPID != 0) {
                    //选择上级计划
                    apiUrl = "TrainPlan/GetSingle?TPID=" + data.TPPID;
                    iscor = 1;
                }
                else {
                    //选择集团计划
                    apiUrl = "CorpPlan/GetCorpPlanDetail?cpid=" + data.CPID;
                }
                $.ajax({
                    url: ApiUrl + apiUrl,
                    type: 'get',
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            if (iscor != 0) {
                                //选择上级计划
                                $("#PrePlanName").val(data.Data.TPName);
                            }
                            else {
                                //选择集团计划
                                if (data.Data[0] != undefined) {
                                    $("#PrePlanName").val(data.Data[0].CPName);
                                }
                            }
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
            }
            var tempList = [];
            function SetTextFromTree(v) {
                for (var i = 0; i < v.length; i++) {
                    var c = v[i];
                    tempList.push({ id: c.id, title: c.title });
                    temp_deptId_List.push(c.id);
                    var a = $("#selectDatas").val();
                    if (a != "") { a += ","; }
                    $("#selectDatas").val(a + c.title);
                    if (c.children != undefined) {
                        if (c.children.length > 0) {
                            SetTextFromTree(c.children);
                        }
                    }
                }
            }
            function setTree()//选择信息列表中 信息时 调用该方法  并为temp_deptId_List赋值
            {
                eleTree.setChecked('eleTreeid', temp_deptId_List);
            }
            var el_tree;
            $("#selectDatas").on("click", function (e) {
                e.stopPropagation();
                loadTree();
                $(".eleTree").toggle();
            });
            function loadTree() {
                el_tree =
                    eleTree.render({
                        elem: '.eleTree',
                        id: 'eleTreeid',
                        data: dataSelect,
                        defaultExpandAll: false,
                        expandOnClickNode: false,
                        highlightCurrent: true
                        , checkStrictly: true
                        , showCheckbox: true
                        , oncheck: function (obj) {
                            $("#selectDatas").val("");
                            temp_deptId_List = [];
                            tempList = [];
                            SetTextFromTree(el_tree.getChecked());
                        }
                    });
            }
            function showList() {
                var swhere = JSON.stringify({
                    TPName: $("#TPName").val(),
                    TPReleaseStart: $("#TPReleaseStart").val(),
                    TPReleaseEnd: $("#TPReleaseEnd").val(),
                    //TPDescribe: $("#TPDescribe").val(),
                    //TPIsRelease: $("#TPIsRelease").val(),
                    IsUse: 1,
                    self: 0
                });
                table.render({
                    elem: '#dataList'
                    , url: ApiUrl + contollerName + '/Search'
                    , id: "dataList"
                    , headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    }
                    , page: true
                    , cols: [[
                        { type: 'checkbox' },
                        { field: 'TPID', title: '编号', sort: true, hide: true },
                        { field: 'TPName', title: '名称'},
                        {
                            field: 'TPReleaseStart', title: '开始时间', width: 110, templet: function (d) {
                                return d.TPReleaseStart.substring(0, 10);
                            },
                        },
                      

                        
                        {
                            field: 'TPReleaseEnd', title: '结束时间', width: 110, templet: function (d) {
                                return d.TPReleaseEnd.substring(0, 10);
                            },
                        },
                        //{ field: 'TPDesignUserID', title: '设计人员id', hide: true },
                        //{ field: 'TPDesignUserName', title: '设计人员姓名' },
                        //{ field: 'TPAddUserID', title: '添加人员id', hide: true },
                        //{ field: 'TPAddUserName', title: '添加人员姓名' },
                        //{
                        //    field: 'TPAddDateTime', title: '添加人员时间', width: 120, templet: function (d) {
                        //        return d.TPAddDateTime.substring(0, 10);
                        //    },
                        //},
                        { field: 'TPDepID', title: '计划部门', hide: true },
                        { field: 'CPID', title: '集团计划ID', hide: true },
                        { field: 'DepLevel', title: '制订计划部门层级', hide: true },
                        { field: 'TPDesignUserName', title: '制订人', width: 130 },
                        {
                            field: 'IsCheck', title: '审核', width: 80, templet: function (d) {
                                return d.IsCheck == "0" ? "未审核" : "已审核";
                            }
                        },
                        //{
                        //    field: 'TPIsRelease', title: '发布', width: 80, templet: function (d) {
                        //        return d.TPIsRelease == "0" ? "未发布" : "已发布";
                        //    }
                        //},
                        { field: 'Remarks', title: '备注', width: 100 },
                        {
                            field: 'AnnexName', title: '附件', event: 'download', width: 230, templet: function (d) {
                                return '<div><a href="' + DownUrl + d.AnnexUrl + '" class="layui-table-link" style="color:blue">' + (d.AnnexName == null ? '' : d.AnnexName) + '</a></div>';
                            }
                        }
                    ]]
                    , where: { swhere: swhere }
                    , parseData: function (res) { //res 即为原始返回的数据
                        return {
                            "code": res.StatusCode, //解析接口状态
                            "msg": res.Info, //解析提示文本
                            "count": res.Count, //解析数据长度
                            "data": res.Data //解析数据列表
                        };
                    },
                    response: { statusCode: 200 },//规定成功的状态码，默认：0
                    event: true,
                    page: true,
                    done: function (res, curr, count) {
                        //如果是异步请求数据方式，res即为你接口返回的信息。
                        //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                        if (res.data != null) {
                            var p = $(".layui-laypage-skip").find("input[type=text]").val();
                            var c = $(".layui-laypage-limits select").find("option:selected").text().substring(0, 2);
                            var k = (Number(p) - 1) * Number(c);
                            for (var i = 0; i < res.data.length; i++) {
                                var item = res.data[i];
                                var ix = item.Row - 1 - k;
                                $(".layui-table-body table tbody tr[data-index=" + ix + "]").attr("style", dataRowColor[item.TPDepLevel]);
                            }
                        }

                        if (res.code == 403) {
                            layer.alert(res.msg, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                    }
                });
            }
            showList();
            $(function () {
                $("#SendNext").click(function () {
                    if (selectCurrentID == 0) {
                        layer.msg("请选择要下发的计划！");
                        return;
                    }
                    if (selectCurrentIsCheckStatus == 0) {
                        layer.msg("请先审核计划！");
                        return;
                    }
                    PlanSend();
                });
                $("del").hide();
                document.getElementById("edit").style.display = "none";
                document.getElementById("edit").style.display = "inline";
                $("#sreach").click(function () {
                    showList();
                })
            })
            PageInit();
            function clearForm() {
                $("textarea").val("");
                $("input").val("");
                $("#TPIsRelease").val("");
                $("#TPName").val("");
            }
            function GetSingleInfo(data) {
                GetSinglePrePlanOrCorp(data);
                $("#TPName").val(data.TPName);
                $("#TPDescribe").val(data.TPDescribe);
                $("#TPDescribeContent").val(data.TPDescribeContent);;
                var star = data.TPReleaseStart.substring(0, data.TPReleaseStart.length - 3).split('T');
                var end = data.TPReleaseEnd.substring(0, data.TPReleaseEnd.length - 3).split('T');
                $("#TPReleaseStart").val(star[0] + " " + star[1]);
                $("#TPReleaseEnd").val(end[0] + " " + end[1]);
                $("#TPIsRelease").val(data.TPIsRelease);
                if (iscor != 0) {
                    if (data.TPPID != null) {
                        prePlanId = data.TPPID;
                    }
                }
                GetSingleCourseContent(data.TPID);
                CPID = data.CPID;
                currentInfoDeptLevelId = data.TPDepLevel;
                currentInfoDeptId = data.TPDepID;
                $("#Remarks").val(data.Remarks);
                //var r = GetDept(currentInfoDeptId);
                //if (r == 1) {
                //    if (data.TPSendDepID != null) {
                //        if (data.TPSendDepID.indexOf(',') > -1) {
                //            var tpids = data.TPSendDepID.split(',');
                //            for (var i = 0; i < tpids.length; i++) {
                //                temp_deptId_List.push(Number(tpids[i]));
                //            }
                //        }
                //        else {
                //            temp_deptId_List.push(Number(data.TPSendDepID));
                //        }
                //        setTree();
                //    }
                //}
                //add by cjh
                selectCurrentIsCheckStatus = data.IsCheck;
                selectCurrentIsReleaseStatus = data.TPIsRelease;
            }

            ///按钮操作 开始
            //监听行单击事件（单击事件为：rowDouble）
            table.on('row(dataList)', function (obj) {
                var checked = false;
                var objcheck = $(obj.tr.selector).find("td").eq(0).find(".layui-table-cell").eq(0).find("div").eq(0);
                if (selectIDs.indexOf(obj.data.TPID) > -1) {
                    objcheck.removeClass("layui-form-checked");
                }
                else {
                    objcheck.addClass("layui-form-checked"); checked = true;
                }
                if (checked) {
                    if (obj.data.TPID != undefined) {
                        selectCurrentID = obj.data.TPID;
                        selectIDs.push(obj.data.TPID);
                        selectobjs.push(obj.data);
                        GetSingleInfo(obj.data);
                    }
                    else {
                        selectIDs = [];
                        selectCurrentID = 0;
                        selectobjs = [];
                        var dataList = table.checkStatus("dataList").data;
                        for (var i = 0; i < dataList.length; i++) {
                            var item = dataList[i];
                            selectobjs.push(item);
                            selectIDs.push(item.TPID);
                            if (i == dataList.length - 1) {
                                GetSingleInfo(item);
                                selectCurrentID = item.TPID;
                            }
                        }
                    }
                }
                else {
                    if (obj.data.TPID != undefined) {
                        selectIDs.splice(selectIDs.indexOf(obj.data.TPID), 1);
                        for (var i = 0; i < selectobjs.length; i++) {
                            if (selectobjs[i].TPID == obj.data.TPID) {
                                if (i == selectobjs.length - 1) {
                                    selectCurrentID = 0;
                                    selectCurrentName = "";
                                    if (i > 0) {
                                        if (selectobjs[i - 1].TPID != undefined) {
                                            selectCurrentID = selectobjs[i - 1].TPID;
                                            GetSingleInfo(selectobjs[i - 1]);
                                        }
                                    }
                                    else {
                                        clearForm(); selectCurrentID = 0;
                                    }
                                }
                                selectobjs.splice(i, 1);
                                break;
                            }
                        }
                        if (selectIDs <= 0) {
                            //temp_deptId_List = [];
                            //var r = GetDept(cuurentDeptId);
                            //if (r == 1) {
                            //    setTree();
                            //}
                        }
                    }
                    else {
                        selectIDs = [];
                        selectCurrentID = 0;
                        selectobjs = [];
                        clearForm();
                        temp_deptId_List = [];
                        //var r = GetDept(cuurentDeptId);
                        //if (r == 1) {
                        //    setTree();
                        //}
                    }
                }
            });
            table.on('tool(dataList)', function (obj) {
                var data = obj.data;
                if (obj.event === 'download') {
                    console.log("单击下载事件");


                    $.ajax({
                        url: ApiUrl + "TrainFileDownLog/Add2",
                        type: 'get',
                        //dataType: 'json',
                        cache: false,
                        data: {
                            filename: data.AnnexName
                        },
                        headers: {
                            "userid": JSON.parse(window.localStorage.authInfo).UserId,
                            "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                        },
                        success: function (data) {
                            console.log("下载成功！");
                        }
                    });
                }
            });
            table.on('checkbox(dataList)', function (obj) {
                if (obj.data.AutoID == undefined) {
                    selectIDs = [];
                    selectCurrentID = 0;
                    selectobjs = [];
                    if (obj.checked) {
                        var dataList = table.checkStatus("dataList").data;
                        for (var i = 0; i < dataList.length; i++) {
                            var item = dataList[i];
                            selectobjs.push(item);
                            selectIDs.push(item.TPID);
                            if (i == dataList.length - 1) {
                                GetSingleInfo(item);
                                selectCurrentID = item.TPID;
                            }
                        }
                    }
                    else {
                        selectIDs = [];
                        selectCurrentID = 0;
                        selectobjs = [];
                        clearForm();
                        temp_deptId_List = [];
                        //var r = GetDept(cuurentDeptId);
                        //if (r == 1) {
                        //    setTree();
                        //}
                    }
                }
            });

            $("#find").click(function () {
                showList();
            });

            $("#reset").click(function () {
                reset();
            });
            function reset() {
                clearForm();
                temp_deptId_List = [];
                selectCurrentID = 0;
            }
            //校验数据
            function CheckData() {
                if ($("#TPName").val().trim() == "") {
                    layer.msg("请输入计划名称！");
                    return false;
                }
                if ($("#TPReleaseStart").val().trim() == "") {
                    layer.msg("请输入发布计划开始时间！");
                    return false;
                }
                if ($("#TPReleaseEnd").val().trim() == "") {
                    layer.msg("请输入发布计划结束时间！");
                    return false;
                }
                return true;
            }
            //获得数据
            function GetFormData() {
                var TPName = $("#TPName").val();//计划名称
                var ID = CPID;//prePlanId;//集团id
                var TPPID = 0;// prePlanId;// prePlanId;//上级计划id
                if (iscor == 1) { TPPID = prePlanId; }
                //var TPDescribe = $("#TPDescribe").val();
                var TPReleaseStart = $("#TPReleaseStart").val();
                var TPReleaseEnd = $("#TPReleaseEnd").val();
                var Remarks = $("#Remarks").val();
                //var TPDescribeContent = $("#TPDescribeContent").val()
                return model = {
                    TPName: TPName,
                    CPID: ID,
                    TPPID: TPPID,
                    TPDescribe: '',
                    TPReleaseStart: TPReleaseStart,
                    TPReleaseEnd: TPReleaseEnd,
                    //TPSendDepID: temp_deptId_List.toString(),
                    TPIsRelease: false,
                    IsCheck: false,
                    IsUse: true,
                    Remarks: Remarks,
                    TPDescribeContent: ''
                }
            }
            //获得数据
            var tpid;
            function GetFormDataContainTPID() {
                var TPName = $("#TPName").val();//计划名称
                var ID = CPID;//prePlanId;//集团id
                var TPPID = 0;// prePlanId;// prePlanId;//上级计划id
                if (iscor == 1) { TPPID = prePlanId; }
                var TPDescribe = $("#TPDescribe").val();
                var TPReleaseStart = $("#TPReleaseStart").val();
                var TPReleaseEnd = $("#TPReleaseEnd").val();
                var Remarks = $("#Remarks").val();
                return model = {
                    TPID:tpid,
                    TPName: TPName,
                    CPID: ID,
                    TPPID: TPPID,
                    TPDescribe: TPDescribe,
                    TPReleaseStart: TPReleaseStart,
                    TPReleaseEnd: TPReleaseEnd,
                    //TPSendDepID: temp_deptId_List.toString(),
                    TPIsRelease: false,
                    IsCheck: false,
                    IsUse: true,
                    Remarks: Remarks
                }
            }
            //判断当前 能否操作该信息
            function GetOperate(operRatetype, pcurrentInfoDeptLevelId) {
                //operRatetype:操作类型     pcurrentInfoDeptLevelId:当前需要操作的信息的  部门级别
                //operRatetype[1:修改，2：删除,3:审核,4:取消审核,5:发布 6:取消发布]
                var result = true;
                if (currentDeptLevelId > pcurrentInfoDeptLevelId) {
                    switch (operRatetype) {
                        case 1:
                            layer.msg("您没有权限，不能修改上级" + ModleNameTip + "");
                            result = false;
                            break;
                        case 2:
                            layer.msg("您没有权限，不能删除上级" + ModleNameTip + "");
                            result = false;
                            break;
                        case 3:
                            layer.msg("您没有审核权限，不能对该条信息进行审核");
                            result = false;
                            break;
                        case 4:
                            layer.msg("您没有取消审核权限，不能对该条信息进行取消审核");
                            result = false;
                            break;
                        case 5:
                            layer.msg("您没有发布信息权限，不能对该条信息进行发布");
                            result = false;
                            break;
                        case 6:
                            layer.msg("您没有取消发布权限，不能对该条信息进行取消发布");
                            result = false;
                            break;
                    }
                }
                return result;
            }
            //编辑保存
            form.on('submit(edit)', function (formdata) {
                if (selectCurrentID <= 0) {
                    add();
                }
                else {
                    edit();
                }
            });
            function edit()
            {
                if (!GetOperate(1, currentInfoDeptLevelId)) { return; }
                if (!CheckData()) { return; }
                var model = GetFormData();
                model.TPID = selectCurrentID;
              
                var rList1 = GetItems($("#insertContent1"), vList1);
                var rList2 = GetItems($("#insertContent2"), vList2);
                if (rList1.length <= 0 && rList2.length <= 0) {
                    layer.msg("请输入课程内容/每周两题!"); return;
                }
                //编辑保存 selectCurrentID
                $.ajax({
                    url: ApiUrl + contollerName + "/Edit",
                    type: 'post',
                    dataType: 'json',
                    data: {
                        'vM_Trainplan': model, 'vList1': rList1
                        , 'vList2': rList2
                    },
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    success: function (data) {
                        if (data.StatusCode == 200 && data.Count != 0) {
                            tpid = data.Data;
                            $("#addupload").click();
                            layer.alert(data.Info, { icon: 6 }, function (index) {
                                layer.close(index); reset();
                                location.reload();
                            })
                        }
                        else if (data.StatusCode == 403) {
                            top.layer.alert(data.Info + ",请重新登录！", { closeBtn: 0 }, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });

            }
            //删除
            $("#del").click(function () {

                if (!GetOperate(2, currentInfoDeptLevelId)) { return; }
                if (selectIDs.length == 0) {
                    layer.msg("请选择要删除的" + ModleNameTip + "！");
                    return;
                }
                if (selectCurrentIsCheckStatus == 1) {
                    layer.msg("已审核的" + ModleNameTip + "不能删除！");
                    return;
                }
                //if (selectCurrentIsReleaseStatus == 1) {
                //    layer.msg("已发布的" + ModleNameTip + "不能删除！");
                //    return;
                //}
                layer.confirm('确定要删除吗,已审核或发布的将不会执行删除?', function (index) {
                    var delList = '';
                    for (var i = 0; i < selectIDs.length; i++) {
                        delList += selectIDs[i] + ',';
                    }
                    delList = delList.substring(0, delList.length - 1);

                    $.ajax({
                        url: ApiUrl + contollerName + "/DelList",
                        type: 'get',
                        cache: false,
                        headers: {
                            "userid": JSON.parse(window.localStorage.authInfo).UserId,
                            "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                        },
                        data: { delidlist: delList },
                        success: function (data) {
                            if (data.StatusCode == 200) {
                                layer.alert(data.Data, { icon: 6 }, function (index) {
                                    layer.close(index);
                                    location.reload();
                                })
                            }
                            else if (data.StatusCode == 403) {
                                layer.alert(data.Info, function () {
                                    top.location.href = "http://" + top.location.host + "/login.html";
                                })
                            }
                            else {
                                layer.msg(data.Info);
                            }
                        }
                    });


                    //删除 selectIDs
                    layer.close(index);
                });
            });
            //审核
            $("#check").click(function () {
                //审核 selectIDs
                //alert("审核");

                if (!GetOperate(3, currentInfoDeptLevelId)) { return; }
                if (selectCurrentID == 0) {
                    layer.msg("请选择要审核的" + ModleNameTip + "！");
                    return;
                }
                if (selectCurrentIsCheckStatus == 1) {
                    layer.msg("选择的" + ModleNameTip + "已审核！");
                    return;
                }
                $.ajax({
                    url: ApiUrl + contollerName + "/UpdatePlanStatus",
                    type: 'get',
                    cache: false,
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    data: { mark: 'C', value: '1', wherevalue: selectCurrentID },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            layer.alert("审核成功", { icon: 6 }, function (index) {
                                layer.close(index);
                                location.reload();
                            })
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                //location.href = './login.html';
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });

            });
            //取消审核
            $("#uncheck").click(function () {
                if (!GetOperate(4, currentInfoDeptLevelId)) { return; }
                if (selectCurrentID == 0) {
                    layer.msg("请选择要取消审核的" + ModleNameTip + "！");
                    return;
                }
                if (selectCurrentIsCheckStatus == "0") {
                    layer.msg("选择的" + ModleNameTip + "未审核！");
                    return;
                }

                layer.confirm('确定要取消审核吗?', function (index) {
                    //取消审核 selectIDs
                    //alert("已取消审核");


                    $.ajax({
                        url: ApiUrl + contollerName + "/UpdatePlanStatus",
                        type: 'get',
                        cache: false,
                        headers: {
                            "userid": JSON.parse(window.localStorage.authInfo).UserId,
                            "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                        },
                        data: { mark: 'C', value: "0", wherevalue: selectCurrentID },
                        success: function (data) {
                            if (data.StatusCode == 200) {
                                layer.alert("取消审核成功", { icon: 6 }, function (index) {
                                    layer.close(index);
                                    location.reload();
                                })
                            }
                            else if (data.StatusCode == 403) {
                                layer.alert(data.Info, function () {
                                    top.location.href = "http://" + top.location.host + "/login.html";
                                })
                            }
                            else {
                                layer.msg(data.Info);
                            }
                        }
                    });


                    layer.close(index);
                });
            });
            //发布
            $("#release").click(function () {
                //alert("release");
                if (!GetOperate(4, currentInfoDeptLevelId)) { return; }
                if (selectCurrentID == 0) {
                    layer.msg("请选择要发布的" + ModleNameTip + "！");
                    return;
                }
                if (selectCurrentIsCheckStatus == "0") {
                    layer.msg("选择的" + ModleNameTip + "未审核！");
                    return;
                }
                if (selectCurrentIsReleaseStatus == 1) {
                    layer.msg("选择的" + ModleNameTip + "已发布！");
                    return;
                }
                $.ajax({
                    url: ApiUrl + contollerName + "/UpdatePlanStatus",
                    type: 'get',
                    cache: false,
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    data: { mark: 'R', value: '1', wherevalue: selectCurrentID },
                    success: function (data) {
                        if (data.StatusCode == 200) {
                            layer.alert("发布成功", { icon: 6 }, function (index) {
                                layer.close(index);
                                location.reload();
                            })
                        }
                        else if (data.StatusCode == 403) {
                            layer.alert(data.Info, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
                //发布 selectIDs
            });
            //取消发布
            $("#unrelease").click(function () {
                if (!GetOperate(6, currentInfoDeptLevelId)) { return; }
                if (selectCurrentID == 0) {
                    layer.msg("请选择要取消发布的" + ModleNameTip + "！");
                    return;
                }
                if (selectCurrentIsReleaseStatus == 0) {
                    layer.msg("选择的" + ModleNameTip + "未发布！");
                    return;
                }
                layer.confirm('确定要取消发布吗?', function (index) {
                    //conso.log("已取消发布");

                    $.ajax({
                        url: ApiUrl + contollerName + "/UpdatePlanStatus",
                        type: 'get',
                        cache: false,
                        headers: {
                            "userid": JSON.parse(window.localStorage.authInfo).UserId,
                            "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                        },
                        data: { mark: 'R', value: "0", wherevalue: selectCurrentID },
                        success: function (data) {
                            if (data.StatusCode == 200) {
                                layer.alert("取消发布成功", { icon: 6 }, function (index) {
                                    layer.close(index);
                                    location.reload();
                                })
                            }
                            else if (data.StatusCode == 403) {
                                layer.alert(data.Info, function () {
                                    top.location.href = "http://" + top.location.host + "/login.html";
                                })
                            }
                            else {
                                layer.msg(data.Info);
                            }
                        }
                    });

                    layer.close(index);
                    //取消发布 selectIDs
                });
            });
            //选择文件
            //选完文件后不自动上传
            upload.render({
                elem: '#test8'
                , url: ApiUrl + "TrainPlan/AddAndFileUpload"
                , headers: {
                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                }
                //, choose: function (obj) {
                //    this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                //}
                , before: function (obj) {
                    this.data = GetFormDataContainTPID();//携带额外的数据
                    //var index = layer.load(); //开始上传之后打开load层
                }
                , exts: 'jpg|png|gif|bmp|jpeg|doc|docx|xls|xlsx|ppt|pptx'
                , auto: false
                , accept: 'file'
                //,multiple: true
                , bindAction: '#addupload'
                , done: function (res, index, upload) {
                    console.log(res);
                    if (res.code == 0) { //上传成功
                        //layer.msg(res.msg);
                        //upload.reload();
                    }
                    if (res.code == 601) { //上传成功

                    }
                }
            });

            var tpid;
            function add()
            {
                if (!CheckData()) { return; }
                var rList1 = GetItems($("#insertContent1"), vList1);
                var rList2 = GetItems($("#insertContent2"), vList2);
                if (rList1.length <= 0 && rList2.length <= 0) {
                    layer.msg("请输入课程内容/每周两课!"); return;
                }
                $.ajax({
                    url: ApiUrl + contollerName + "/Add",
                    type: 'post',
                    dataType: 'json',
                    cache: false,
                    data: {
                        'vM_Trainplan': GetFormData(), 'vList1': rList1
                        , 'vList2': rList2
                    },
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    success: function (data) {
                        if (data.StatusCode == 200 && data.Count != 0) {
                            tpid = data.Data;
                            $("#addupload").click();
                            layer.alert("添加保存成功", { icon: 6 }, function (index) {
                                layer.close(index); reset();
                                location.reload();
                            })
                        }
                        else if (data.StatusCode == 403) {
                            top.layer.alert(data.Info + ",请重新登录！", { closeBtn: 0 }, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
            }
         
        });
    </script>
</body>
</html>